<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<div id="app">
			<p>总数:{{total}}</p>
			<my-component @listenadd="handleGetTotal" @listenreduce="handleGetTotal"></my-component>
		</div>
		<script src="js/vue2.5.js"></script>
		<script>
//			有问题,看的不太明白
			var vm = new Vue({
				el:'#app',
				data:{
					total:0
				},
				components:{
					'my-component':{
						template:'<div><button @click="add">+1</button><button @click="reduce">-1</button></div>',
						data(){
							return{
								count : 0
							}
						},
						methods:{
							add:function(){
								this.count++;
								this.$emit('listenadd',this.count);
							},
							reduce:function(){
								this.count--;
								this.$emit('listenreduce',this.count);
							}
						}
					}
				},
				methods:{
					handleGetTotal :function(total){
						this.total = total;
					}
				}
			})
		</script>
	</body>
</html>
